package com.focusai.efairy.ui.activity.maintain;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.focusai.efairy.R;
import com.focusai.efairy.model.maintain.MaintainItem;
import com.focusai.efairy.network.Image.ImageLoaderFactory;
import com.focusai.efairy.ui.base.SwipeBackBaseActivity;
import com.focusai.efairy.ui.widget.ninegridview.NineGridTestLayout;
import com.focusai.efairy.utils.ActivityUtils;
import com.focusai.efairy.utils.StrByCodeUtils;

import java.util.ArrayList;

/**
 * Created by luo_guangwen on 2017/10/11.
 */

public class MaintainRecordDetailActivity extends SwipeBackBaseActivity {
    public static final String KEY_MAINTAIN_ITEM = "key_maintain_item";
    private ImageView ivAvater;
    private TextView textHeadName;
    private TextView textHeadContent;
    private TextView textHeadTip;
    private TextView textContent;
    private NineGridTestLayout nineGridTestLayout;
    private TextView textTimes;
    private MaintainItem maintainItem;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.item_warn_detail);
        initView();
        setDefaultValues();
    }

    @Override
    protected void initView() {
        textHeadName = findView(R.id.text_heard_name);
        textHeadContent = findView(R.id.text_heard_content);
        textHeadTip = findView(R.id.text_heard_tip);
        textTimes = findView(R.id.text_food_time);
        textContent = findView(R.id.text_content);
        ivAvater = findView(R.id.iv_user_avater);
        nineGridTestLayout = findView(R.id.layout_nine_grid);
    }

    @Override
    protected void setDefaultValues() {
        setCenterTitleName("维护记录详情");
        if (getIntent() != null) {
            maintainItem = (MaintainItem) getIntent().getSerializableExtra(KEY_MAINTAIN_ITEM);
        }
        if (maintainItem == null) {
            showToast("传递的数据为空");
            finish();
        }
        findView(R.id.ll_content).setVisibility(View.GONE);
        loadData();
    }

    @Override
    protected void loadData() {
        findView(R.id.ll_content).setVisibility(View.VISIBLE);
        textHeadName.setText(maintainItem.efairyuser_nickname);
        textHeadContent.setText(maintainItem.efairydevice_name);
        textContent.setText(maintainItem.efairymtrecord_content);
        textTimes.setText(maintainItem.efairymtrecord_time);
        String tip = StrByCodeUtils.getStrMaintainByType(maintainItem.efairymtrecord_mt_type_id) + "  " +
                StrByCodeUtils.getStrMaintainByHandId(maintainItem.efairymtrecord_mt_type_id,maintainItem.efairymtreord_mt_handle_id);
        textHeadTip.setText(tip);
        ImageLoaderFactory.getImageLoader().loadImage(mContext, ivAvater, maintainItem.efairyuser_headimg_url,R.drawable.user_default_icon,false);
        nineGridTestLayout.setUrlList(maintainItem.efairymtrecord_imgurl_list);
        nineGridTestLayout.setOnImageItemClick(new NineGridTestLayout.OnImageItemClick() {
            @Override
            public void onImageItemClick(int position, String url, ArrayList<String> urlList) {
                ActivityUtils.openPhotoPagerActivity(MaintainRecordDetailActivity.this,0,position,urlList,false);
            }
        });
    }
}
